#这是用来测试python配置文件x.ini操作命令的程序

#配置文件读写参数需引用
import configparser

# 读写配置文件类，需通过文件名初始化文件指针
class ConfigFile(object):

    def __init__(self,fileName):

       self.fileName = fileName
       self.cf = configparser.ConfigParser()
    
    #读参数文件函数
    #入口参数分别为参数类别，参数名
    def readSystem(self,paraKind,paraName):
        self.cf.read(self.fileName)
        paraValue = self.cf.get(paraKind,paraName)
        return paraValue
    
    #简单中文测试失败，复杂改进无需学习
    def rwIniFilezhongwen(self):
       result = self.cf.get('中文', '变量测试')
       return result
    
    #写参数文件函数
    #入口参数分别为参数类别，参数名，参数值
    def writeSystem(self,paraKind,paraName,paraValue):
        self.cf.set(paraKind,paraName,paraValue)
        with open(self.fileName,"w") as configfilename:
            self.cf.write(configfilename)


# 读写配置文件测试类
class FileOperTest(object):
    
    def __init__(self) -> None:
        pass

    # 测试读写配置文件
    def testConfigRW(self) -> None:
        config_file=ConfigFile('configure.ini')
        print(config_file.readSystem('system','testpara'))
        config_file.writeSystem('system','testpara','656')
        print(config_file.readSystem('system','testpara'))




